#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
    Module Documentation
    here
"""

# Created by  : Zhang Chengdong
# Create Date : 2024/11/29 01:47 

__author__ = "Zhang Chengdong"
__copyright__ = "Copyright 2024. Large scale model"
__credits__ = ['Zhang Chengdong']

__liscence__ = "MIT"
__version__ = "1.0.1"
__maintainer__ = "Zhang Chengdong"
__status__ = "Production"

import json
import os
import sys

sys.path.append("../")
from nonmodel.predict_data import predict_main
from predict import determine_model_use

def get_test_data(data_path: str):
    """
    :param data_path:
    :return:
    """
    with open(data_path, 'rb') as f:
        data = json.load(f)
    return data


def nonlinear_predict_part(data: dict, model_code: str = "CI_10001194-CI_10001073-CI_10001091"):
    """
    非线形模型预测部分
    :param data:
    :param model_code:
    :return
    """
    current_dir = os.path.dirname(os.path.abspath(__file__))
    parent_dir = os.path.dirname(current_dir)
    # save_model_path = os.path.join(parent_dir, "models")
    save_model_path = "../models"
    model_result = {}
    model_type_suffix, not_have_data_type = determine_model_use(data)
    for item in model_type_suffix:
        model_info = {
            "model_type": item,
            "model_path": os.path.join(save_model_path, "CatBoost", model_code + "_{}.pkl".format(item)),
            "first_suffix": model_type_suffix[item]['use_name'],
            "second_suffix": model_type_suffix[item]['code']
        }
        y_pred_info = predict_main(data, model_info)
        if list(y_pred_info.keys())[0] not in model_result:
            model_result.update(y_pred_info)
        else:
            first_key_name = list(y_pred_info.keys())[0]
            model_result[first_key_name].update(y_pred_info[first_key_name])
    model_result.update(not_have_data_type)
    return {"nonlinear": model_result}


if __name__ == '__main__':
    data = get_test_data('test_data.json')
    nonlinear_info = nonlinear_predict_part(data)
    print(nonlinear_info)
